#!/usr/bin/python
#-*-coding:utf-8-*-
# coding=utf-8
import server.ccl_server as server
import constant.constant_value as constant
import json
from bs4 import BeautifulSoup as parserUtils
import entry.publish_content_bean as publishContentBean

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

def send(subject , content , channelId ,typeId ,uid ,author ):
    url = constant.cms_api_domain + constant.cms_api_uri
    print "in send cms thread moudle"

    contentBean = publishContentBean.publishContentBean()
    contentBean.requestClass = "contentService"
    contentBean.requestType = "publishContent"
    contentBean.token = constant.cms_api_token
    contentBean.title = subject
    contentBean.txt = content
    contentBean.channelId = channelId
    contentBean.typeId = typeId
    contentBean.uid = uid
    contentBean.author = author
    try:
        ccl_server = server.CclServer(url, json.dumps(contentBean,default=contentBean.convert_to_builtin_type))
        response = ccl_server.send_json_post()
        soup = parserUtils(response,from_encoding="gbk")
        string_soup = soup.text
        print string_soup;
        response_dict = json.loads(string_soup)
        return response_dict['code']
    except Exception as err:
        print err;
        return "";

if __name__ =="__main__":
    send("first thread ".encode("GBK"),"my first thread".encode("GBK"),"11","1","1","fly".encode("GBK"));
    pass